package net.gldwork.srcpdr;

import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

public class ContentBlock {
	public static final String INDENT = "    ";
	private List<String> lines = new LinkedList<String>();

	public ContentBlock addLine(String code, int indentCount) {
		StringBuffer line = new StringBuffer();
		for (int i = 0; i < indentCount; i++) {
			line.append(INDENT);
		}
		line.append(code);
		lines.add(line.toString());
		return this;
	}

	public ContentBlock addBlankLine() {
		lines.add("\n");
		return this;
	}

	public ContentBlock addLine(String code) {
		return addLine(code, 0);
	}

	public String toString() {
		return StringUtils.join(lines, "\n");
	}

	public ContentBlock append(ContentBlock cb, int indentCount) {
		List<String> childLines = cb.getLines();
		for (String line : childLines) {
			addLine(line, indentCount);
		}
		return this;
	}

	public List<String> getLines() {
		return lines;
	}

	public void setLines(List<String> lines) {
		this.lines = lines;
	}

}
